home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_01 / cips.c < prev    next >
C/C++ Source or Header  |  1992-04-13  |  19KB  |  516 lines

  1.  
  2.  
  3.  
  4.  
  5.        /***********************************************
  6.        *
  7.        *       file d:\cips\cips.c
  8.        *
  9.        *       Functions: This file contains
  10.        *          main
  11.        *          clear_text_screen
  12.        *          show_menu
  13.        *          show_image
  14.        *
  15.        *       Purpose:
  16.        *          This file contains the main calling
  17.        *          routine in the C Image Processing System.
  18.        *
  19.        *       External Calls:
  20.        *          numcvrt.c - get_integer
  21.        *          gin.c - get_image_name
  22.        *          rtiff.c - read_tiff_image
  23.        *          tiff.c - read_tiff_header
  24.        *          rstring.c - read_string
  25.        *          display.c - display_image
  26.        *                      display_menu_for_display_image
  27.        *          pi.c - print_image
  28.        *          ht.c - display_using_halftoning
  29.        *                 get_threshold_value
  30.        *          djet.c - print_graphics_image
  31.        *                   get_graphics_caption
  32.        *          hist.c - display_menu_for_histogram
  33.        *                   calculate_area_histogram
  34.        *                   print_histogram
  35.        *                   show_histogram
  36.        *          edge.c - detect_edges
  37.        *                   get_edge_options
  38.        *                   quick_edge
  39.        *          edge2.c - homogeneity
  40.        *                    difference_edge
  41.        *                    contrast_edge
  42.        *          edge3.c - gaussian_edge
  43.        *                    enhance_edges
  44.        *          filter.c - filter_image
  45.        *                     median_filter
  46.        *                     get_filter_options
  47.        *          addsub.c - add_image_array
  48.        *                     subtract_image_array
  49.        *          cutp.c - cut_image_piece
  50.        *                   paste_image_piece
  51.        *                   check_cut_and_paste_limits
  52.        *          rotate.c - rotate_flip_image_array
  53.        *          scale.c - zoom_image_array
  54.        *                    shrink_image_array
  55.        *
  56.        *       Modifications:
  57.        *          26 June 1990 - created
  58.        *
  59.        *************************************************/
  60.  
  61. #include "d:\cips\cips.h"
  62.  
  63.  
  64. short the_image[ROWS][COLS];
  65. short out_image[ROWS][COLS];
  66.  
  67. main()
  68. {
  69.  
  70.    char caption[80],
  71.         color_transform[80],
  72.         low_high[80],
  73.         method[80],
  74.         monitor_type[80],
  75.         name[80],
  76.         name2[80],
  77.         name3[80],
  78.         rep[80],
  79.         zoom_shrink[80];
  80.  
  81.  
  82.    int  color                = 99,
  83.         detect_threshold     = 1,
  84.         detect_type          = 1,
  85.         display_colors       = 16,
  86.         filter_type          = 1,
  87.         high                 = 100,
  88.         horizontal           = 3,
  89.         i                    = 0,
  90.         ie                   = 1,
  91.         ie2                  = 1,
  92.         ie3                  = 1,
  93.         il                   = 1,
  94.         il2                  = 1,
  95.         il3                  = 1,
  96.         image_colors         = 256,
  97.         invert               = 0,
  98.         j                    = 0,
  99.         length               = 3,
  100.         le                   = COLS+1,
  101.         le2                  = COLS+1,
  102.         le3                  = COLS+1,
  103.         ll                   = ROWS+1,
  104.         ll2                  = ROWS+1,
  105.         ll3                  = ROWS+1,
  106.         not_finished         = 1,
  107.         print                = 0,
  108.         response             = 99,
  109.         rotation_type        = 1,
  110.         scale                = 2,
  111.         show_hist            = 0,
  112.         size                 = 7,
  113.         threshold            = 128,
  114.         vertical             = 3,
  115.         width                = 3;
  116.  
  117.    long     mean_of_pixels;
  118.    unsigned long histogram[256];
  119.    short    low_hi_filter[3][3];
  120.    struct   tiff_header_struct image_header;
  121.  
  122.  
  123.    clear_text_screen();
  124.  
  125.    strcpy(color_transform, "Straight mode");
  126.    strcpy(monitor_type, "VGA");
  127.    strcpy(low_high, "l");
  128.    strcpy(zoom_shrink, "z");
  129.    strcpy(method, "r");
  130.  
  131.    strcpy(name,  "d:/pix/adam256.tif");
  132.    strcpy(name2, "d:/pix/output.tif");
  133.    strcpy(name3, "d:/pix/output.tif");
  134.  
  135.      while(not_finished){
  136.  
  137.         show_menu();
  138.  
  139.         get_integer(&response);
  140.  
  141.         switch (response){
  142.  
  143.         case 1:/* display image header */
  144.          get_image_name(name);
  145.          read_tiff_header(name, &image_header);
  146.          printf("\n\nCIPS> The image header is:");
  147.          printf("\n\t\twidth=%ld length=%ld  start=%ld  bits=%ld",
  148.               image_header.image_width,
  149.               image_header.image_length,
  150.               image_header.strip_offset,
  151.               image_header.bits_per_pixel);
  152.          printf("\nCIPS> Hit Enter to continue");
  153.          read_string(rep);
  154.         break;
  155.  
  156.         case 2:/* display image numbers */
  157.          get_image_name(name);
  158.          get_parameters(&il, &ie, &ll, &le);
  159.          read_tiff_image(name, the_image, il, ie, ll, le);
  160.          show_image(the_image, il, ie);
  161.          break;
  162.  
  163.         case 3:   /* print image numbers */
  164.          get_image_name(name);
  165.          get_parameters(&il, &ie, &ll, &le);
  166.          read_tiff_image(name, the_image, il, ie, ll, le);
  167.          print_image(the_image, name, 1, 1, 1, 100, 18,
  168.                      il, ie);
  169.         break;
  170.  
  171.         case 4:   /* display image */
  172.          get_image_name(name);
  173.          read_tiff_header(name, &image_header);
  174.          get_parameters(&il, &ie, &ll, &le);
  175.          display_menu_for_display_image(&image_colors,
  176.                    &display_colors, &invert,
  177.                    color_transform, monitor_type,
  178.                    &show_hist);
  179.          display_image(name, the_image, il, ie,
  180.                    ll, le, &image_header, monitor_type,
  181.                    color_transform, invert,
  182.                    image_colors, display_colors, show_hist);
  183.         break;
  184.  
  185.         case 5:   /* display image using halftoning */
  186.          get_image_name(name);
  187.          read_tiff_header(name, &image_header);
  188.          get_parameters(&il, &ie, &ll, &le);
  189.          display_menu_for_display_image(&image_colors,
  190.                    &display_colors, &invert,
  191.                    color_transform, monitor_type,
  192.                    &show_hist);
  193.          get_threshold_value(&threshold, &print);
  194.          display_using_halftoning(the_image, name,
  195.                    il, ie, ll, le, threshold,
  196.                    invert, image_colors, &image_header,
  197.                    monitor_type, print, show_hist,
  198.                    color_transform);
  199.         break;
  200.  
  201.         case 6:   /* print graphics image */
  202.          get_image_name(name);
  203.          read_tiff_header(name, &image_header);
  204.          get_parameters(&il, &ie, &ll, &le);
  205.          display_menu_for_display_image(&image_colors,
  206.                    &display_colors, &invert,
  207.                    color_transform, monitor_type,
  208.                    &show_hist);
  209.          get_graphics_caption(caption);
  210.          print_graphics_image(the_image, out_image, name,
  211.                    il, ie, ll, le, image_colors,
  212.                    invert, caption, show_hist,
  213.                    color_transform);
  214.         break;
  215.  
  216.         case 7:   /* print or display histogram numbers */
  217.          get_image_name(name);
  218.          read_tiff_header(name, &image_header);
  219.          get_parameters(&il, &ie, &ll, &le);
  220.          display_menu_for_histogram(&print, &vertical,
  221.                    &horizontal);
  222.          calculate_area_histogram(histogram, vertical,
  223.                    horizontal, the_image, name,
  224.                    il, ie, ll, le);
  225.          if(print == 0)
  226.             show_histogram(histogram);
  227.          if(print == 1)
  228.             print_histogram(histogram, name);
  229.         break;
  230.  
  231.         case 8:  /* perform edge detection */
  232.            printf("\nCIPS> Enter input image name\n");
  233.            get_image_name(name);
  234.            printf("\nCIPS> Enter output image name\n");
  235.            get_image_name(name2);
  236.            get_parameters(&il, &ie, &ll, &le);
  237.            get_edge_o